<template>
  <div id="app">
    {{ loginState }} -- {{ $store.state.user.login }}
    <input type="text" placeholder="登录的账号" v-model="loginname">
    <input type="text" placeholder="密码" v-model="password">
    <button @click="login">登录</button>
  </div>
</template>
<script>
import { mapActions, mapState } from 'vuex'
export default {
  computed: {
    ...mapState({
      loginState: state => state.user.loginState
    })
  },
  data () {
    return {
      loginname: '',
      password: ''
    }
  },
  methods: {
    ...mapActions({
      loginFn: 'user/loginAction'
    }),
    login () {
      this.loginFn({ loginname: this.loginname, password: this.password }).then(data => {
        if (data === '10010') {
          console.log('该账号还未注册')
        } else if (data === '10011') {
          console.log('密码错误')
        } else {
          console.log('登录成功')
        }
      })
    }
  }
}
</script>
